/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import clasesJXTA.AdministradorJXTA;
import clasesJXTA.NodoRemoto;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Arkan
 */
public class DialogoCompartirFoto extends JDialog implements ActionListener, Observer
{
    private final static String ACEPTAR = "Aceptar";
    
    private final static String CANCELAR = "Cancelar";
    
    private InterfazFotosP2P principal;
    
    private boolean ok;
    
    private JLabel labIDFoto;
    
    private JLabel labPeronas;
    
    private JTextField txtIDFoto;
    
    private JTextField txtPersonas;
    
    private JButton butAceptar;
    
    private JButton butCancelar;
    
    public DialogoCompartirFoto( InterfazFotosP2P ventana )
    {
        principal = ventana;
        ok = false;
        
        setTitle( "Propiedades Foto" );
        setSize( 350, 110 );
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        setResizable( false );
        setModal( true );
        setLocationRelativeTo( principal );
        setLayout( new GridLayout( 3, 2 ) );
        
        labIDFoto = new JLabel( "ID:" );
        add( labIDFoto );
        
        txtIDFoto = new JTextField( );
        add( txtIDFoto );
        
        labPeronas = new JLabel( "Personas (separadas por ,):" );
        add( labPeronas );
        
        txtPersonas = new JTextField( );
        add( txtPersonas );
        
        butAceptar = new JButton( ACEPTAR );
        butAceptar.setActionCommand( ACEPTAR );
        butAceptar.addActionListener( this );
        add( butAceptar );
        
        butCancelar = new JButton( CANCELAR );
        butCancelar.setActionCommand( CANCELAR );
        butCancelar.addActionListener( this );
        add( butCancelar );
    }

    public boolean darOK( )
    {
        return ok;
    }
    
    public String darID( )
    {
        return txtIDFoto.getText( ); 
    }
    
    public String darPersonas( )
    {
        return txtPersonas.getText( );
    }
    
    public void actionPerformed( ActionEvent e )
    {
        String comando = e.getActionCommand( );
        
        if( comando.equals( ACEPTAR ) )
        {
            if( !txtIDFoto.getText( ).equals( "" ) && !txtPersonas.getText( ).equals( "" ) )
            {
                ok = true;
                dispose( );
            }
            else
            {
                JOptionPane.showMessageDialog( this, "Debe llenar todos los campos", "Información", JOptionPane.INFORMATION_MESSAGE );
            }
        }
        else if( comando.equals( CANCELAR ) )
        {
            dispose( );
        }
    }

    @Override
    public void update(Observable o, Object ob) {
         if( o instanceof AdministradorJXTA )
        {
            ArrayList<NodoRemoto> lista = ( ArrayList<NodoRemoto> )ob;
            System.out.println("Encontre una foto con el mismo id");
            
        }
    }
}
